package com.qs.imp;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.qs.dao.ConnectionManager;
import com.qs.entity.MoonMessage;
import com.qs.inter.MoonMessageInt;

public class MoonMessageImp implements MoonMessageInt{
	Connection conn;
	PreparedStatement ps;
	ResultSet rs;

	public int addMoonMessage(MoonMessage moonmessage) throws Exception {
		conn = ConnectionManager.getConnction();
		String sql = "insert into MoonMessage(MoonId,UserName,MoonMessage) values(?,?,?)";
		ps = conn.prepareStatement(sql);
		ps.setInt(1, moonmessage.getMoonId());
		ps.setString(2, moonmessage.getUserName());
		ps.setString(3, moonmessage.getMessage());
		int i = ps.executeUpdate();
		return i;
	}

	public List sMoonMessage(int MoonId) throws Exception {
		List list = new ArrayList<MoonMessage>();
		conn = ConnectionManager.getConnction();
		String sql = "select * from MoonMessage where MoonId = ?";
		ps = conn.prepareStatement(sql);
		ps.setInt(1, MoonId);
		rs = ps.executeQuery();
		while(rs.next()){
			MoonMessage moonmessage1 = new MoonMessage();
			moonmessage1.setMoonId(rs.getInt("MoonId"));
			moonmessage1.setMoonMessageId(rs.getInt("MoonMessageId"));
			moonmessage1.setUserName(rs.getString("UserName"));
			moonmessage1.setMessage(rs.getString("MoonMessage"));
			list.add(moonmessage1);
		}
		return list;	
	}

	
}
